package Testing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RMISecurityManager;

import javax.sound.midi.ControllerEventListener;

import DbObjects.Person;
import MockDb.StaticMockDb;
import MockDb.StaticMockDbInitiailizer;
import Remote.ISimpleService;
import Remote.PersonService;

public class Server
{
	private static ISimpleService<Person> service;
	
	public static void main(String[] args) throws RemoteException
	{	
		try {
			System.setSecurityManager(new
                    RMISecurityManager());

				PersonService p = null;
				if(args == null || args.length == 0)
					p = new PersonService(new StaticMockDb(new StaticMockDbInitiailizer()));
				else
					p = new PersonService(new StaticMockDb(new StaticMockDbInitiailizer(Long.parseLong(args[0]))));
				Naming.rebind("RMIPerson", p);
		      System.out.println ("Server is ready.");
		    } catch (Exception e) {
		      System.out.println ("Server failed: " + e);
		    }
	}
}